import { defineConfig, loadEnv, type ConfigEnv, type UserConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from "path";
import viteCompression from "vite-plugin-compression";
import { WrppEnv } from "./src/utils/gloenv";
// https://vite.dev/config/
export default defineConfig((mode:ConfigEnv):UserConfig=>{
  const env=loadEnv(mode.mode,process.cwd())
  const viteEnv=WrppEnv(env)
  return{
    plugins: [
      react(),
      {
        name:'my-plu',
        transform(code){
          return code.replace(/console\.log/g,'console.info')
        }
      },
      viteCompression({
        verbose:true,
        disable:false,
        threshold:10240,
        algorithm:'gzip',
        ext:'.gz'
      })
    ],
    resolve:{
      alias:{
        "@":resolve(__dirname,"src")

      }
    },
    server:{
      host:'0.0.0.0',
      port:viteEnv.VITE_PORT,
      open:viteEnv.VITE_OPEN,
      proxy:{
        '/api':{
          target:viteEnv.VITE_API_URL,
          changeOrigin:true,
          rewrite:path=>path.replace(/^\/api/,'')
        }
      }

    },
    esbuild:{
      drop:['console','debugger']
    }
  }
  
})
